<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <div id="app">
            <component :is="currentComponent"></component>
            <button @click="currentComponent='ComponentB'">切换为componentB</button>
            <button @click="currentComponent='ComponentA'">切换为componentA</button>
        </div>
        <script src="vue.js"></script>
        <script>
        var vm = new Vue({
            el:'#app',
            data:{currentComponent:'ComponentA'},
            components:{
                ComponentA:{
                    template:'<div>ComponentA</div>'
                },
                ComponentB:{
                    template:'<div>ComponentB</div>'
                }
            }
           
        });
    </script>
    </body>
</html>